Back to Contents Previous Next
11. Dragging or double-clicking files
Whenever a file (or directory or application) is ‘dragged and dropped’ onto a window (or the iconbar icon) belonging to your application - or, indeed, just double-clicked on - then
FNuser_loaddata
(path$,window%,icon%,ftype$,workx%,worky%)
is called automatically. Note that its default return is 0, which is discussed later below.
The parameters are:
path$
is the full pathname of the file that has been dragged/double-clicked (the ‘source’ file).
window%
is the window handle where the drag ended. (It will be 0 if the file was double-clicked rather than dragged.)
icon%
is the icon number where the drag ended. (It will be -1 if no icon is involved, or if the file was double-clicked rather than dragged.) Most of the time you would only need to check the window handle, but the icon handle can be used for drop-boxes. These are boxes with text in saying something like: “Drop file to load here”.
ftype$
is the filetype of the source file. Eg: for text files it is “FFF”. Files have a three character hexadecimal filetype, but directories are “1000”, and applications are “2000”. (Note that letters willbe in upper-case, and if the hex number is less than &100 then there will be leading zeros added automatically e.g. filetype &AF will appear as “0AF”)
workx%
,worky%
are the work area coordinates (in the window window%
) where the drag ended. (These will both be -1 if the file was double-clicked on rather than dragged.)
With these values passed to you by Dr Wimp it is up to you to add any particular code to access or manipulate the file/directory/application.
The other important point to note is that you, the programmer, must also help the Wimp by letting it know if you are responding to the dragging/double-clicking of the file - and this is the role of the return from the user-function, entirely similar to that employed when saving data to a file via a ‘save box’ - see Section 2.7.
So, if you respond to the dragging/double-clicking of any file you must return a 1 from this user-function - otherwise the default 0 must be returned. This is vital because the return value is used by DrWimp to send a message to the Filer saying that you are taking action on it.
Here is an example piece of code for loading the contents of a text file line-by-line into an array (for simplicity it assumes the file is not empty and that the array is large enough):
DEF FNuser_loaddata(path$,window%,icon%,ftype$,workx%,worky%)
LOCAL return%,L%
return%=0
IF ftype$=“FFF” THEN
file%=OPENIN(path$)
L%=1
REPEAT
A$(L%)=GET$#file%
L%+=1
UNTIL EOF#file%
CLOSE#file%
return%=1
ENDIF
=return%
What this does is to check if the dragged/double-clicked file is a text file and, if so, load each of its lines into an array called A$
(which you will need to create in PROCuser_initialise
).
Try altering !MyApp so it can load in a text file, then using the save box, allow the user to save the text file to somewhere else. All you have to do is alter the save code so it saves the contents of the array.
When a file is double-clicked it can also be made to load in your application first, if it isn't already loaded. The only thing you need to add to achieve this is a line like the following in your application’s !Run file:
Set Alias$@RunType_xxx <Obey$Dir>.!Run %%*0
Change “xxx” for the hex value of the filetype you are using, eg. “FFF” for text files.
Note that, when a file is loaded in this way, the parameters window%
and icon%
passed to FNuser_loaddata
will be 0 and -1 respectively and the workx%/worky%
coordinates will both be -1. See above. You could therefore use these values to filter double-click loading if you wished.
Top of page Back to Contents Previous Next